package scientistengineer.blogspot.affrpor;


import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class IconTextAdapter extends ArrayAdapter<RowIconText> {
	
	int layoutResourceId;
	RowIconText data[] = null;
	Context context;
	
	
	public IconTextAdapter(Context context, int resource, RowIconText [] data) 
	{
		super(context, resource, data);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.layoutResourceId = resource;
		this.data = data;
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View row = convertView;
		IconTextRowHolder holder = null;
		
		if(row==null)
		{
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent,false);
			
			holder = new IconTextRowHolder();
			
			holder.ivIcon =(ImageView) row.findViewById(R.id.iconImageView);
			holder.tvTitle = (TextView) row.findViewById(R.id.titleTextView);
			
			row.setTag(holder);
		}
		else
		{
			holder = (IconTextRowHolder)row.getTag();
		}
		
		RowIconText singleRow = data[position];
		holder.ivIcon.setImageResource(singleRow.iconImageView);
		holder.ivIcon.getLayoutParams().height = 120;
		holder.ivIcon.getLayoutParams().width = 120;
		holder.tvTitle.setText(singleRow.textView);
		
		return row;
	}
	
	public static class IconTextRowHolder
	{
		ImageView ivIcon;
		TextView tvTitle;	
	}

}
